//
//  MOHintView.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/7/8.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOHintView.h"

@interface MOHintView ()

@property(nonatomic,strong)UIView *backView;

@property(nonatomic,copy)NSString *contentStr;

@property(nonatomic,strong)UIButton *sureButton;

@property(nonatomic,strong)UIButton *deleteButton;

@end

@implementation MOHintView


- (instancetype)initWithFrame:(CGRect)frame andContentStr:(NSString *)contentStr{
    self = [super initWithFrame:frame];
    if(self) {
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.7];
        
        self.contentStr = contentStr;
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [button addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        
        [self addSubview:self.backView];
        
        if ([contentStr rangeOfString:@"开发中"].location!=NSNotFound) {
            self.deleteButton.hidden = YES;
            self.sureButton.centerX = _backView.width/2;
        }
        
    }
    return self;
}

#pragma mark -- 取消
-(void)clickCancelButton
{
    self.frame = CGRectMake(0, 0, 0, 0);
    self.backView.frame = CGRectMake(0, 0, 0, 0);
    
    if (self.clickCancelButtonBlock) {
        self.clickCancelButtonBlock();
    }
}

#pragma mark -- 确定
-(void)clickSureButton
{
    self.frame = CGRectMake(0, 0, 0, 0);
    self.backView.frame = CGRectMake(0, 0, 0, 0);
    
    if (self.clickSureButtonBlock) {
        self.clickSureButtonBlock();
    }
}

#pragma mark -- 懒加载
-(UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWConversions(280), 189)];
        _backView.centerX = SCREEN_WIDTH/2;
        _backView.centerY = SCREEN_HEIGHT/2;
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 2.0;
        _backView.layer.borderWidth = 2;
        _backView.layer.borderColor = KGrayColor_ededed.CGColor;
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 15, _backView.width - 30, 35)];
        titleLabel.font = [UIFont boldSystemFontOfSize:18];
        titleLabel.text = @"提示";
        titleLabel.textColor = KBlackColor_2A2A2A;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [_backView addSubview:titleLabel];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, titleLabel.bottom + 25, _backView.width-30, 45)];
        label.text = self.contentStr;
        label.font = FONT_SIZE(16);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = KBlackColor_2A2A2A;
        label.font = FONT_SIZE(16);
        CGFloat height = [NSString labelAutoCalculateRectWith:label.text WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(_backView.width-30, MAXFLOAT)].height;
        label.height = height;
        label.numberOfLines = 0;
        [_backView addSubview:label];
        
        _deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(20, label.bottom + 20, 75, 35)];
        [_deleteButton setTitle:@"取消" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:KBlueColor_2C94FF forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        _deleteButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_backView addSubview:_deleteButton];
        
        _sureButton = [[UIButton alloc]initWithFrame:CGRectMake(_backView.width - 75 - 20, label.bottom + 20, 75, 35)];
        [_sureButton setTitle:@"确定" forState:UIControlStateNormal];
        [_sureButton setTitleColor:KBlueColor_2C94FF forState:UIControlStateNormal];
        [_sureButton addTarget:self action:@selector(clickSureButton) forControlEvents:UIControlEventTouchUpInside];
        _sureButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_backView addSubview:_sureButton];
        
        _backView.height = _sureButton.bottom + 15;
        _backView.centerY = SCREEN_HEIGHT/2;
    }
    return _backView;
}



@end
